const http = require('http');
const fs = require("fs");
const path = require("path");

http.createServer((req,res)=>{
    var readable;
    if(process.argv[2]){
        var filePath = path.join(__dirname, process.argv[2]);
        if(fs.existsSync(filePath)){
            readable = fs.createReadStream(filePath);
            readable.pipe(res);
        }else{
            res.end("文件路径不存在");
        }
    }else{
        readable = fs.createReadStream(path.join(__dirname, "/fileReader3.js"));
        readable.pipe(res);
    }
}).listen(8081)
console.log(("server is listening 8081").slice(7));